package cn.iocoder.yudao.module.member.assets.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.member.assets.service.AppMemberDigitalAssetsService;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyIncreasingPresetVO;
import cn.iocoder.yudao.module.member.assets.vo.AppCryptocurrencyOverviewRespVO;
import cn.iocoder.yudao.module.member.assets.vo.AppDigitalAssetsConvertSubmitVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 数字资产")
@RestController
@RequestMapping("/member/digital-assets")
@Validated
public class AppMemberCryptocurrencyController {
    @Resource
    private AppMemberDigitalAssetsService appMemberDigitalAssetsService;

    @GetMapping("/cryptocurrency/overview")
    @Operation(summary = "获得联盟豆概览")
    public CommonResult<AppCryptocurrencyOverviewRespVO> getCryptocurrencyOverview() {
        return success(appMemberDigitalAssetsService.getCryptocurrencyOverview(getLoginUserId()));
    }

    @PostMapping("/cryptocurrency/origin-not-increment")
    @Operation(summary = "联盟豆转换为收益豆")
    public CommonResult<Boolean> doCryptocurrencyNotIncrementSubmit(@Valid @RequestBody AppDigitalAssetsConvertSubmitVO submitVO) {
        appMemberDigitalAssetsService.submitCryptocurrencyOriginToIncrement(getLoginUserId(), submitVO.getAmount());
        return success(true);
    }

    @GetMapping("/cryptocurrency/increasing-preset-list")
    @Operation(summary = "联盟豆兑换投入预设列表")
    public CommonResult<List<AppCryptocurrencyIncreasingPresetVO>> getCryptocurrencyIncreasingPresetList() {
        return success(appMemberDigitalAssetsService.getCryptocurrencyIncreasingPresetList(getLoginUserId()));
    }

    @PostMapping("/cryptocurrency/origin-to-increment")
    @Operation(summary = "联盟豆兑换投入收益池")
    public CommonResult<Boolean> doCryptocurrencyIncreasingSubmit(@Valid @RequestBody AppDigitalAssetsConvertSubmitVO submitVO) {
        appMemberDigitalAssetsService.submitCryptocurrencyOriginToIncreasing(getLoginUserId(), submitVO.getAmount());
        return success(true);
    }

    @PostMapping("/cryptocurrency/origin-to-money")
    @Operation(summary = "联盟豆兑换零钱")
    public CommonResult<Boolean> doCryptocurrencyToMoneySubmit(@Valid @RequestBody AppDigitalAssetsConvertSubmitVO submitVO) {
        appMemberDigitalAssetsService.submitCryptocurrencyOriginToMoney(getLoginUserId(), submitVO.getAmount());
        return success(true);
    }

    @PostMapping("/cryptocurrency/increment-to-money")
    @Operation(summary = "收益豆兑换零钱")
    public CommonResult<Boolean> doCryptocurrencyIncrementToMoneySubmit(@Valid @RequestBody AppDigitalAssetsConvertSubmitVO submitVO) {
        appMemberDigitalAssetsService.submitCryptocurrencyIncrementToMoney(getLoginUserId(), submitVO.getAmount());
        return success(true);
    }

}